package edu.sctu;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

/**
 * Servlet
 * Created by Administrator on 2018-5-15.
 */
public class TestServlet extends HttpServlet{

    // 重写doGet()
    @Override
    protected void doGet(HttpServletRequest req,
                         HttpServletResponse resp) throws ServletException, IOException {

        DataBase dataBase = new DataBase();
        List<User> list = null;
        try {
            list = DataBase.getUserList();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        try {
            list = dataBase.getUserList();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        // 易出错点2
        req.setAttribute("list", list);

        // 连接JSP和servlet的关键点。
        req.getRequestDispatcher("/test02.jsp").forward(req,resp);
    }

}
